package ntu.metaweb.update;

import java.io.IOException;
import java.net.URL;

import ntu.metaweb.XMLMarshaller;
import ntu.p2p.dht.messaging.DHTObjectDifference;
import rice.p2p.commonapi.rawserialization.InputBuffer;
import rice.p2p.commonapi.rawserialization.OutputBuffer;

public class PageAverageRating implements DHTObjectDifference {
	protected static final short TYPE = 6;
	
	public URL url;
	public double averageRating;
	
	public PageAverageRating(URL url, double averageRating) {
		this.url = url;
		this.averageRating = averageRating;
	}
	
	protected PageAverageRating(InputBuffer buf) {
		try {
			this.url = (URL) XMLMarshaller.getInstance().unmarshall(buf.readUTF());
			this.averageRating = buf.readDouble();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static DHTObjectDifference build(InputBuffer buf) {
		return new NewComment(buf);
	}
	
	@Override
	public void serialize(OutputBuffer buf) throws IOException {
		buf.writeShort(TYPE);
		buf.writeDouble(averageRating);
	}

}